package com.iskny.framework.admin.interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.core.ActionInvocation;
import com.jfinal.core.Controller;
import com.jfinal.core.JFinal;

/**
 * 自动json 方式输出
 * @author 伟强
 *
 */
public class JsonRenderInterceptor implements Interceptor {

	private String paraSeparator= JFinal.me().getConstants().getUrlParaSeparator();
	public JsonRenderInterceptor(){
	}
	@Override
	public void intercept(ActionInvocation ai) {
		Controller c = ai.getController();
		ai.invoke();
		String uri = c.getRequest().getRequestURI();
		if(uri.endsWith(paraSeparator+"json")||uri.endsWith("/json")){
			c.renderJson();
		}
	}

}
